package com.zhiyou100.review.day011.baseclasslibrary;

/**
 * @packageName: Teacher
 * @className: com.zhiyou100.review.day011.baseclasslibrary
 * @Description: TODO 老师类
 * @author: yang
 * @date: 6/17/20
 */
public class Teacher {
    private String name;
    private int age;
    private char gender;
    private double salary;

    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof Teacher)) {
            // 判断类型 如果不是 Teacher 类型的
            return false;
        }
        Teacher teacher = (Teacher) (obj);
        // 转换 为 teacher

        // 如果名字相同 年龄相同 性别相同 工资相差10 为同一个人 返回true
        return this.name.equals(teacher.name) && this.age == teacher.age && Math.abs(this.salary - teacher.salary) <= 10 && this.gender == teacher.gender;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public char getGender() {
        return gender;
    }

    public void setGender(char gender) {
        this.gender = gender;
    }

    public double getSalary() {
        return salary;
    }

    public void setSalary(double salary) {
        this.salary = salary;
    }

    /**
     * @Description: TODO 提供一个无参数的构造方法：所有属性随机：sex只限男女  salary取值3000.0--5000.0 age取值25-35 名字要求：4个字符：字符可以是大写字母/小写字母/数字
     * @name: Teacher
     * @param: []
     * @return:
     * @date: 6/17/20 17:40
     * @author: yang
     */
    public Teacher() {
        this.gender = randomGender();
        this.salary = randomSalary();
        this.age = randomAge();
        this.name = randomName();
    }

    /**
     * @Description: TODO 随机性别 男 或 女
     * @name: randomGender
     * @param: []
     * @return: char
     * @date: 6/17/20 17:43
     * @author: yang
     */
    public char randomGender() {
        return randomInt(0, 1) == 0 ? '女' : '男';
    }

    /**
     * @Description: TODO   salary 取值3000.0--5000.0
     * @name: randomSalary
     * @param: []
     * @return: double
     * @date: 6/17/20 18:31
     * @author: yang
     */
    public double randomSalary() {
        return Double.parseDouble(randomInt(3000, 5000) + (String.valueOf((randomInt(0, 9) * 0.1 + randomInt(0, 9) * 0.01))));
    }

    /**
     * @Description: TODO  age取值25-35
     * @name: randomAge
     * @param: []
     * @return: int
     * @date: 6/17/20 19:22
     * @author: yang
     */
    public int randomAge() {
        return randomInt(25, 35);
    }

    /**
     * @Description: TODO  名字要求：4个字符：字符可以是大写字母/小写字母/数字
     * @name: randomName
     * @param: []
     * @return: java.lang.String
     * @date: 6/17/20 19:25
     * @author: yang
     */
    public String randomName() {
        StringBuilder stringBuilder = new StringBuilder();
        int max = 4;
        for (int i = 0; i < max; i++) {
            int randomInt = randomInt(0, 3);
            // 随机一个 0 1 2 的字符
            if (randomInt == 0) {
                stringBuilder.append(randomNumbers());
            } else if (randomInt == 1) {
                stringBuilder.append(randomCapital());
            } else {
                stringBuilder.append(randomLowercase());
            }
        }
        return stringBuilder.toString();
    }

    /**
     * @Description: TODO 随机一个数字
     * @name: randomNumbers
     * @param: []
     * @return: java.lang.String
     * @date: 6/17/20 19:37
     * @author: yang
     */
    public String randomNumbers() {
        return ((char) (randomInt('0', '9'))) + "";
    }

    /**
     * @Description: TODO 随机一个小写字母
     * @name: randomLowercase
     * @param: []
     * @return: java.lang.String
     * @date: 6/17/20 19:36
     * @author: yang
     */
    public String randomLowercase() {
        return ((char) (randomInt('a', 'z'))) + "";
    }

    /**
     * @Description: TODO 随机一个大写字母
     * @name: randomCapital
     * @param: []
     * @return: java.lang.String
     * @date: 6/17/20 19:33
     * @author: yang
     */
    public String randomCapital() {
        return ((char) (randomInt('A', 'Z'))) + "";
    }

    /**
     * @name: randomOfMinToMax
     * @param: double min,double max
     * @description: TODO  生成 [min,max]的随机数
     * @date: 2020/2/21 5:17 下午
     * @return: int
     */
    public static int randomInt(int min, int max) {

        return min + (int) (Math.random() * (max - min + 1));
    }


    @Override
    public String toString() {
        return name + " 老师是" + (2020 - age) + " 年生，今年 " + age + " 岁" + " 工资 " + salary + " 元";
    }

    public static void main(String[] args) {
        for (int i = 0; i < 100; i++) {
            Teacher teacher = new Teacher();
            System.out.println(teacher);
        }

    }

}
